<template>
  <div class="editform">
    <!-- 基本信息 -->
    <div class="duty">所属经销商</div>
    <FormPanel ref="FormPanel0" :list="formList0" :cols="3" labelWidth="130" formType="show" :isSubmitBtn="false" />
    <!-- 基本信息 -->
    <div class="duty">基本信息</div>
    <div class="clearfix">
        <div class="FormPanelDiv">
            <FormPanel ref="FormPanel" :list="formList" :cols="3" labelWidth="130" formType="show" :isSubmitBtn="false" />
        </div>
        <div class="imgDiv" v-show="imgUrl?true:false">
            <img style="width:100%;" :src="imgUrl" alt="">
        </div>
    </div>

    <div :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'center'
        }">
        <el-button size="small" type="primary"       @click="closeDialog">返 回</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getJsonTree } from '@/utils/index';
import {getComOrgTreeList,getPresetRole} from '@/api/common/org/employeeInfo';
import {getEmployeeInfo,postEmployeeInfo,} from '@/api/common/auth/employeeAuth'
import {searchEmployee,} from '@/api/common/auth/dealerStaff';

export default {
  name:'showForm',
  mixins: [dictionary],
  props:['rowData','type'],
  data() {
    return {
      formList: this.createFormList(),
      formList0:this.createFormList0(),
    //formList2:this.createFormList2(),
      imgUrl:null,
    };
  },
  
  methods: {
    
    createFormList() {
      return [
        {
          type: 'DATE',
          label: '入职日期',
          fieldName: 'entryTime',
          placeholder: '',
          initialValue: '',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '员工编号',
          fieldName: 'employeeNo',
          placeholder: '',
          initialValue: '',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '登录账号',
          fieldName: 'userCode',
          placeholder: '',
          initialValue: '',
          disabled:true,
        },
        {
          type: 'INPUT_TREE',
          label: '所属部门',
          fieldName: 'orgId',
          placeholder: '所属部门',
          initialValue: '',
          selfCols: 2,
          itemList: [],
          disabled:false,
        },
        {
          type: 'SELECT',
          label: '在职状态',
          fieldName: 'employeeStatus',
          placeholder: '',
          initialValue: '',
          disabled:false,
          itemList: this.createDictList('1008'),
        },
        {
          type: 'DATE',
          label: '离职日期',
          fieldName: 'dimissionDate',
          placeholder: '',
          initialValue: '',
          disabled:true,
        },
        // {
        //   type: 'SELECT',
        //   label: '第一岗位',
        //   fieldName: 'firstPost',
        //   placeholder: '',
        //   initialValue: '',
        //   itemList: this.createDictList('2588'),
        //   disabled:false,
        // },
        // {
        //   type: 'SELECT',
        //   label: '第二岗位',
        //   fieldName: 'secondPost',
        //   placeholder: '',
        //   initialValue: '',
        //   itemList: this.createDictList('2588'),
        //   disabled:false,
        // },
        // {
        //   type: 'SELECT',
        //   label: '第三岗位',
        //   fieldName: 'thirdPost',
        //   placeholder: '',
        //   initialValue: '',
        //   itemList: this.createDictList('2588'),
        //   disabled:false,
        // },
        {
          type: 'INPUT',
          label: '员工姓名',
          fieldName: 'employeeName',
          placeholder: '',
          initialValue: '',
          disabled:false,
        },
        {
          type: 'INPUT',
          label: '手机号码',
          fieldName: 'mobilePhone',
          placeholder: '',
          initialValue: '',
          disabled:false,
        },
        {
          type: 'SELECT',
          label: '性别',
          fieldName: 'gender',
          placeholder: '',
          initialValue: '',
          disabled:false,
          itemList: this.createDictList('1002'),
        },
        {
          type: 'INPUT',
          label: '身份证号',
          fieldName: 'certificateId',
          placeholder: '',
          initialValue: '',
          disabled:true,
        },
        {
          type: 'DATE',
          label: '出生日期',
          fieldName: 'birthday',
          placeholder: '',
          initialValue: '',
          disabled:false,
        },
        {
          type: 'INPUT',
          label: 'Email',
          fieldName: 'eMail',
          placeholder: '',
          initialValue: '',
          disabled:false,
        },
        {
          type: 'INPUT',
          label: '民族',
          fieldName: 'nation',
          placeholder: '',
          initialValue: '',
          maxlength:16,
          disabled:false,
        },
        {
          type: 'SELECT',
          label: '驾驶证级别',
          fieldName: 'drivingLevel',
          placeholder: '',
          initialValue: '',
          disabled:false,
          itemList: [{ text: 'A', value: 'A' },{ text: 'B', value: 'B' },{ text: 'C', value: 'C' }],
        },
        {
          type: 'SELECT',
          label: '教育程度',
          fieldName: 'degreeEdu',
          placeholder: '',
          disabled:false,
          initialValue: '',
          itemList: this.createDictList('4049'),
        },
        {
          type: 'INPUT',
          label: '年龄',
          fieldName: 'age',
          placeholder: '',
          initialValue: '',
          maxlength:3,
          disabled:false,
        },
        {
          type: 'INPUT',
          label: '汽车行业时长（年）',
          fieldName: 'autoTime',
          placeholder: '',
          initialValue: '',
          maxlength:3,
          disabled:false,
        },
        {
          type: 'SELECT',
          label: '是否校企合作院校毕业',
          fieldName: 'cooperationSchool',
          placeholder: '',
          itemList: this.createDictList('1004'),
          initialValue: '',
          disabled:false,
        },
        {
          type: 'INPUT',
          label: '毕业院校',
          fieldName: 'graduateSchool',
          placeholder: '',
          initialValue: '',
          disabled:false,
          maxlength:16,
        },
        {
          type: 'SELECT',
          label: '是否冻结',
          fieldName: 'lockFlag',
          placeholder: '',
          initialValue: '',
          disabled:false,
          itemList: this.createDictList('1004'),
        },
        {
          type: 'INPUT',
          label: '冻结原因',
          fieldName: 'lockCause',
          placeholder: '',
          initialValue: '',
          disabled:true,
          maxlength:32,
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          placeholder: '',
          initialValue: '',
          disabled:false,
          selfCols: 3,
          maxlength:32,
        },
      ];
    },
    /* createFormList0() {
      return [
        {
          type: 'SELECT',
          label: '班组',
          fieldName: 'workgroupId',
          placeholder: '',
          initialValue: '',
          hidden:false,
          itemList: this.createDictList('1004'),
          //rules: [{ required: true, message: '请选择班组', trigger: 'blur' }]
        },{
          type: 'SELECT',
          label: '工种',
          fieldName: 'workerTypeId',
          placeholder: '',
          initialValue: '',
          hidden:false,
          itemList: this.createDictList('8041'),
          //rules: [{ required: true, message: '请选择工种', trigger: 'blur' }]
        },{
          type: 'SELECT',
          label: '技师等级',
          fieldName: 'technicianGrade',
          placeholder: '',
          initialValue: '',
          hidden:false,
          itemList: this.createDictList('8054'),
          //rules: [{ required: true, message: '请选择技师等级', trigger: 'blur' }]
        },{
          type: 'SELECT',
          label: '主工位',
          fieldName: 'maintainStationId',
          placeholder: '',
          initialValue: '',
          hidden:false,
          itemList: this.createDictList('1004'),
          //rules: [{ required: true, message: '请选择主工位', trigger: 'blur' }]
        },{
          type: 'SELECT',
          label: '副工位',
          fieldName: 'deputyStationId',
          placeholder: '',
          initialValue: '',
          hidden:false,
          itemList: this.createDictList('1004'),
          //rules: [{ required: true, message: '请选择副工位', trigger: 'blur' }]
        },
        
      ];
    }, */
    createFormList0() {
      return [
        {
          type: 'INPUT',
          label: '经销商公司',
          fieldName: 'companyName',
          placeholder: '',
          initialValue: '',
          // rules: [{ required: true, message: '请输入登录账号', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '公司代码',
          fieldName: 'companyCode',
          placeholder: '',
          initialValue: '',
          // rules: [{ required: true, message: '请输入员工姓名', trigger: 'blur' },{ min: 0, max: 6, message: '长度在 0 到 6 个字符', trigger: 'blur' }]
        }
      ];
    },
    init(){
      //第一二三岗位数据
      /* getPresetRole().then(res=>{
        // console.log(res,"第一二三岗位数据")
        res.data.map(x=>{
            this.formList.find(item => item.fieldName === 'firstPost').itemList.push({text:x.roleName,value:x.roleId})
            this.formList.find(item => item.fieldName === 'secondPost').itemList.push({text:x.roleName,value:x.roleId})
            this.formList.find(item => item.fieldName === 'thirdPost').itemList.push({text:x.roleName,value:x.roleId})
        })
      })*/

      this.formList0.find(item => item.fieldName === 'companyCode').initialValue = this.rowData.companyCode;
      this.formList0.find(item => item.fieldName === 'companyName').initialValue = this.rowData.companyName;

      searchEmployee(this.rowData.employeeNo,this.rowData.companyId).then(res=>{
        console.log(res,"res")
        this.formList.forEach(x=>{
          x.initialValue=res.data[x.fieldName]
          // if(this.formList.find(item => item.fieldName === 'employeeStatus').initialValue == 10081002){
          //   this.formList[5].disabled =false
          // }
        })
        this.formList.find(item => item.fieldName === 'orgId').initialValue=res.data.orgId
        this.formList.find(item => item.fieldName === 'orgId').placeholder=res.data.orgName
        this.imgUrl = res.data['headPortrait']
      })
      // this.formList.forEach(x=>{
      //   x.rules=[]
      //   x.disabled=true
      // }) 
    },
   
    // 返回
    closeDialog(type) {
      this.$emit('close', false,);
    },
    // 部门树
    async inputTree() {
        const res = await getComOrgTreeList();
        var that = res.data
        that.forEach(el => (el.text = el.text));
        that.forEach(el => (el.value = el.orgId));
        that.forEach(el => (el.parentId = el.parent));
        this.formList.find(item => item.fieldName === 'orgId').itemList = getJsonTree(that);
        console.log(this.formList.find(item => item.fieldName === 'orgId').itemList,"this.formList.find(item => item.fieldName === 'orgId').itemList")
           
    },
  },
  mounted () {
    this.init()
    this.inputTree(); 
  },
};
</script>

<style lang="less" scoped>
.clearfix::after {
  content: '';
  height: 0;
  visibility: hidden;
  clear: both;
  display: block;
}
.clearfix {
  zoom: 1;
}
.editform{
    .FormPanelDiv{
    width: 80%;
    float: left;
    margin-right: 3%;
    }
    .imgDiv{
        width: 12%;
        // min-height: 150px;
        border: 1px solid #000;
        float: left;
        /* position: absolute;
        right: 10%;
        top: 0; */
    }
    .editformBtn{
        text-align: center;
        margin-top: 15px;
    }
    .duty{
      width: 99%;
      height: 30px;
      line-height: 30px;
      margin-bottom: 5px;
      background: #eee;
      text-indent: 5px;
    }
}

</style>
